/*
package com.ssfeng.youxia.services;

import com.ssfeng.youxia.mapper.SessionsMapper;
import com.ssfeng.youxia.model.Sessions;
import com.ssfeng.youxia.shiro.SessionUtils;
import com.ssfeng.youxia.shiro.ShiroUser;
import org.apache.shiro.session.Session;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.util.*;


@Service
public class SessionService {

    private static final Logger logger = LoggerFactory.getLogger(SessionService.class);

    @Autowired
    private EnvironmentService environmentService;

    @Autowired
    private SessionsMapper sessionsMapper;


    */
/***
     * 获取在线用户
     * @return
     *//*

    public  List<Map<String, Object>> getOnlineUsers(){
        List<Map<String, Object>> result = new ArrayList<>();
        List<Sessions> list = sessionsMapper.findAllUserSessions();
        if (!CollectionUtils.isEmpty(list)) {
            for (Sessions sessions : list) {
                String sessionStr = sessions.getSession();
                Session session = SessionUtils.base64DcodeSession(sessionStr);
                ShiroUser user = SessionUtils.getUserFromSession(session);
                if (user == null) {
                    continue;
                }

                Map<String, Object> map = new HashMap<>();
                map.put("userId", user.getUserId());
                map.put("userName", user.getUserName());
                map.put("startTimestamp", session.getStartTimestamp());
                map.put("lastAccessTime", session.getLastAccessTime());
                map.put("host", session.getHost());
                map.put("sessionId", session.getId());
                result.add(map);
            }
        }
        return result;
    }

    */
/***
     * 删除过期session
     * @return
     *//*

    public int deleteExpiredSessions(){
        Long last = System.currentTimeMillis() - Long.parseLong(environmentService.getProperty("globalSessionTimeout"));
        Date date = new Date(last);
        int count=sessionsMapper.deleteExpiredSessions(date);
        return count;
    }

    */
/***
     * 踢出用户
     * @param sessionId
     *//*

    public void kickOutUser(String sessionId) {
        Sessions sessions = sessionsMapper.selectByPrimaryKey(sessionId);
        if (!StringUtils.isEmpty(sessions)) {
            String sessionStr = sessions.getSession();
            Session session = SessionUtils.base64DcodeSession(sessionStr);
            session.setAttribute(SessionUtils.SESSION_KICKOUT_KEY, true);
            sessionStr = SessionUtils.base64EncodeSession(session);
            sessions.setSession(sessionStr);
            sessionsMapper.updateByPrimaryKey(sessions);
        }
    }
}
*/
